Dithering and Halftoning Bitmaps
The color ramp created in the previous section uses thegxRGB32Space
color space, but not all display devices can display 32 bits of color. To optimize the appearance of color on displays with limited numbers of colors, QuickDraw GX allows you to dither shapes--that is, approximate colors that a display device cannot draw, with patterns of similar colors that the display device can draw.The chapter "View-Related Objects" in Inside Macintosh: QuickDraw GX Objects describes dithering in detail.
This section shows how you can use dithering to draw the color ramp shown in
Figure 5-14 on page 5-28.Since dithering is a function of view port objects, you must first determine the view port to which the color ramp is drawn. Since this color ramp is only being drawn to one view port, you can declare an array to hold a single view port reference:
gxViewPort aViewPortList[1];Then you can use theGXGetShapeGlobalViewPorts
function to copy the view port list from the transform object of the color ramp bitmap shape into the view port array:
GXGetShapeGlobalViewPorts(aColorRampBitmapShape, aViewPortList);If the color ramp were being drawn to multiple view ports, you would call this function once specifyingnil
for the view port array to determine the number of view ports, then allocate space to hold the view port references, and then call the function a second time to determine the actual view port references.In the color ramp example, you can use the
GXSetViewPortDither
function to indicate that shapes drawn to this view port should be dithered. This function takes two parameters: a reference to the view port and a dither level, which is described in detail in the chapter "View-Related Objects" in Inside Macintosh: QuickDraw GX Objects. If a view port has a dither level of 2 or greater, QuickDraw GX dithers bitmaps drawn to that view port:
GXSetViewPortDither(aViewPortList[0], 4); /* Dither bitmaps */Figure 5-15 shows how QuickDraw GX draws the dithered color ramp to display devices at two different pixel depths.
Halftoning, which is also described in the chapter "View-Related Objects" in Inside Macintosh: QuickDraw GX Objects, is similar to dithering. To specify halftoning for a view port, you need to create a
gxHalftone
structure. This structure specifies information about how QuickDraw GX should halftone shapes drawn to the view port. Listing 5-7 shows how to create a samplegxHalftone
structure and set the halftone characteristics for the view port of the color ramp bitmap.Listing 5-7 Halftoning a bitmap
gxHalftone aHalfTone; SetCommonColor(&halftoneDots, gxBlack); SetCommonColor(&halftoneBackground, gxWhite); aHalftone.angle = ff(45); aHalftone.frequency = ff(5); aHalftone.method = gxRoundDot; aHalftone.tinting = gxComponent1Tint; aHalftone.dotColor = halftoneDots; aHalftone.backgroundColor = halftoneBackground; aHalftone.tintSpace = gxRGBSpace; GXGetShapeGlobalViewPorts(aBitmapShape, aViewPort); GXSetViewPortHalftone(aViewPort[0], &aHalftone);Figure 5-16 shows three possible results of halftoning the color ramp bitmap. The first example is the result of Listing 5-7--round dots and a dot frequency of 5. The other two examples show the result of halftoning the color ramp bitmap with other dot frequencies and dot shapes.
Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help